package com.ruoyi.web.controller.tongban;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tongban.domain.UsrParental;
import com.ruoyi.tongban.service.IUsrParentalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家长,关联member,为家长的扩展信息Controller
 * 
 * @author ruoyi
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/tongban/parental")
public class UsrParentalController extends BaseController
{
    @Autowired
    private IUsrParentalService usrParentalService;

    /**
     * 查询家长,关联member,为家长的扩展信息列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:parental:list')")
    @GetMapping("/list")
    public TableDataInfo list(UsrParental usrParental)
    {
        startPage();
        List<UsrParental> list = usrParentalService.selectUsrParentalList(usrParental);
        return getDataTable(list);
    }

    /**
     * 导出家长,关联member,为家长的扩展信息列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:parental:export')")
    @Log(title = "家长,关联member,为家长的扩展信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UsrParental usrParental)
    {
        List<UsrParental> list = usrParentalService.selectUsrParentalList(usrParental);
        ExcelUtil<UsrParental> util = new ExcelUtil<UsrParental>(UsrParental.class);
        return util.exportExcel(list, "parental");
    }

    /**
     * 获取家长,关联member,为家长的扩展信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:parental:query')")
    @GetMapping(value = "/{parentalId}")
    public AjaxResult getInfo(@PathVariable("parentalId") Long parentalId)
    {
        return AjaxResult.success(usrParentalService.selectUsrParentalById(parentalId));
    }

    /**
     * 新增家长,关联member,为家长的扩展信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:parental:add')")
    @Log(title = "家长,关联member,为家长的扩展信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UsrParental usrParental)
    {
        return toAjax(usrParentalService.insertUsrParental(usrParental));
    }

    /**
     * 修改家长,关联member,为家长的扩展信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:parental:edit')")
    @Log(title = "家长,关联member,为家长的扩展信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UsrParental usrParental)
    {
        return toAjax(usrParentalService.updateUsrParental(usrParental));
    }

    /**
     * 删除家长,关联member,为家长的扩展信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:parental:remove')")
    @Log(title = "家长,关联member,为家长的扩展信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{parentalIds}")
    public AjaxResult remove(@PathVariable Long[] parentalIds)
    {
        return toAjax(usrParentalService.deleteUsrParentalByIds(parentalIds));
    }
}
